﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace ParticlePlayground
{
	// Token: 0x0200015E RID: 350
	[Serializable]
	public class PaintObjectC
	{
		// Token: 0x06000817 RID: 2071 RVA: 0x0002FA78 File Offset: 0x0002DC78
		public virtual void Initialize()
		{
			this.paintPositions = new List<PaintPositionC>();
			this.brush = new PlaygroundBrushC();
			this.lastPaintPosition = PlaygroundC.initialTargetPosition;
			this.initialized = true;
		}

		// Token: 0x06000818 RID: 2072 RVA: 0x0002FAA4 File Offset: 0x0002DCA4
		public virtual bool Paint(Ray ray, Color32 color)
		{
			if (this.collisionType == COLLISIONTYPEC.Physics3D)
			{
				RaycastHit raycastHit;
				if (Physics.Raycast(ray, out raycastHit, this.brush.distance, this.layerMask))
				{
					this.Paint(raycastHit.point, raycastHit.normal, raycastHit.transform, color);
					this.lastPaintPosition = raycastHit.point;
					return true;
				}
			}
			else
			{
				RaycastHit2D raycastHit2D = Physics2D.Raycast(ray.origin, ray.direction, this.brush.distance, this.layerMask, this.minDepth, this.maxDepth);
				if (raycastHit2D.collider != null)
				{
					this.Paint(raycastHit2D.point, raycastHit2D.normal, raycastHit2D.transform, color);
					this.lastPaintPosition = raycastHit2D.point;
					return true;
				}
			}
			return false;
		}

		// Token: 0x06000819 RID: 2073 RVA: 0x0002FBA0 File Offset: 0x0002DDA0
		public virtual int Paint(Vector3 pos, Vector3 norm, Transform parent, Color32 color)
		{
			PaintPositionC paintPositionC = new PaintPositionC();
			if (parent)
			{
				paintPositionC.parent = parent;
				paintPositionC.initialPosition = parent.InverseTransformPoint(pos);
				paintPositionC.initialNormal = parent.InverseTransformDirection(norm);
			}
			else
			{
				paintPositionC.initialPosition = pos;
				paintPositionC.initialNormal = norm;
			}
			paintPositionC.color = color;
			paintPositionC.position = paintPositionC.initialPosition;
			this.paintPositions.Add(paintPositionC);
			this.positionLength = this.paintPositions.Count;
			if (!this.exceedMaxStopsPaint && this.positionLength > PlaygroundC.reference.paintMaxPositions)
			{
				this.paintPositions.RemoveAt(0);
				this.positionLength = this.paintPositions.Count;
			}
			return this.positionLength - 1;
		}

		// Token: 0x0600081A RID: 2074 RVA: 0x0002FC68 File Offset: 0x0002DE68
		public virtual bool Erase(Vector3 pos, float radius)
		{
			bool result = false;
			if (this.paintPositions.Count == 0)
			{
				return false;
			}
			for (int i = 0; i < this.paintPositions.Count; i++)
			{
				if (Vector3.Distance(this.paintPositions[i].position, pos) < radius)
				{
					this.paintPositions.RemoveAt(i);
					result = true;
				}
			}
			this.positionLength = this.paintPositions.Count;
			return result;
		}

		// Token: 0x0600081B RID: 2075 RVA: 0x0002FCE4 File Offset: 0x0002DEE4
		public virtual bool Erase(int index)
		{
			if (index >= 0 && index < this.positionLength)
			{
				this.paintPositions.RemoveAt(index);
				this.positionLength = this.paintPositions.Count;
				return true;
			}
			return false;
		}

		// Token: 0x0600081C RID: 2076 RVA: 0x0002FD1C File Offset: 0x0002DF1C
		public virtual Vector3 GetPosition(int index)
		{
			index %= this.positionLength;
			return this.paintPositions[index].position;
		}

		// Token: 0x0600081D RID: 2077 RVA: 0x0002FD3C File Offset: 0x0002DF3C
		public virtual Color32 GetColor(int index)
		{
			index %= this.positionLength;
			return this.paintPositions[index].color;
		}

		// Token: 0x0600081E RID: 2078 RVA: 0x0002FD5C File Offset: 0x0002DF5C
		public virtual Vector3 GetNormal(int index)
		{
			index %= this.positionLength;
			return this.paintPositions[index].initialNormal;
		}

		// Token: 0x0600081F RID: 2079 RVA: 0x0002FD7C File Offset: 0x0002DF7C
		public virtual Transform GetParent(int index)
		{
			index %= this.positionLength;
			return this.paintPositions[index].parent;
		}

		// Token: 0x06000820 RID: 2080 RVA: 0x0002FD9C File Offset: 0x0002DF9C
		public virtual Quaternion GetRotation(int index)
		{
			index %= this.positionLength;
			return this.paintPositions[index].parentRotation;
		}

		// Token: 0x06000821 RID: 2081 RVA: 0x0002FDBC File Offset: 0x0002DFBC
		public virtual void Update()
		{
			for (int i = 0; i < this.paintPositions.Count; i++)
			{
				if (!(this.paintPositions[i].parent == null))
				{
					this.Update(i);
				}
			}
		}

		// Token: 0x06000822 RID: 2082 RVA: 0x0002FE10 File Offset: 0x0002E010
		public virtual void Update(int thisPosition)
		{
			thisPosition %= this.positionLength;
			this.paintPositions[thisPosition].position = this.paintPositions[thisPosition].parent.TransformPoint(this.paintPositions[thisPosition].initialPosition);
			this.paintPositions[thisPosition].parentRotation = this.paintPositions[thisPosition].parent.rotation;
		}

		// Token: 0x06000823 RID: 2083 RVA: 0x0002FE88 File Offset: 0x0002E088
		public virtual void RemoveNonParented()
		{
			for (int i = 0; i < this.paintPositions.Count; i++)
			{
				if (this.paintPositions[i].parent == null)
				{
					this.paintPositions.RemoveAt(i);
					i--;
				}
			}
		}

		// Token: 0x06000824 RID: 2084 RVA: 0x0002FEE0 File Offset: 0x0002E0E0
		public virtual bool RemoveNonParented(int thisPosition)
		{
			thisPosition %= this.positionLength;
			if (this.paintPositions[thisPosition].parent == null)
			{
				this.paintPositions.RemoveAt(thisPosition);
				return true;
			}
			return false;
		}

		// Token: 0x06000825 RID: 2085 RVA: 0x0002FF18 File Offset: 0x0002E118
		public virtual void ClearPaint()
		{
			this.paintPositions = new List<PaintPositionC>();
			this.positionLength = 0;
		}

		// Token: 0x06000826 RID: 2086 RVA: 0x0002FF2C File Offset: 0x0002E12C
		public virtual PaintObjectC Clone()
		{
			PaintObjectC paintObjectC = new PaintObjectC();
			if (this.paintPositions != null && this.paintPositions.Count > 0)
			{
				paintObjectC.paintPositions = new List<PaintPositionC>();
				paintObjectC.paintPositions.AddRange(this.paintPositions);
			}
			paintObjectC.positionLength = this.positionLength;
			paintObjectC.lastPaintPosition = this.lastPaintPosition;
			paintObjectC.spacing = this.spacing;
			paintObjectC.layerMask = this.layerMask;
			paintObjectC.collisionType = this.collisionType;
			if (this.brush != null)
			{
				paintObjectC.brush = this.brush.Clone();
			}
			else
			{
				paintObjectC.brush = new PlaygroundBrushC();
			}
			paintObjectC.exceedMaxStopsPaint = this.exceedMaxStopsPaint;
			paintObjectC.initialized = this.initialized;
			return paintObjectC;
		}

		// Token: 0x04000806 RID: 2054
		[HideInInspector]
		public List<PaintPositionC> paintPositions;

		// Token: 0x04000807 RID: 2055
		[HideInInspector]
		public int positionLength;

		// Token: 0x04000808 RID: 2056
		[HideInInspector]
		public Vector3 lastPaintPosition;

		// Token: 0x04000809 RID: 2057
		[HideInInspector]
		public COLLISIONTYPEC collisionType;

		// Token: 0x0400080A RID: 2058
		public float minDepth = -1f;

		// Token: 0x0400080B RID: 2059
		public float maxDepth = 1f;

		// Token: 0x0400080C RID: 2060
		public float spacing;

		// Token: 0x0400080D RID: 2061
		public LayerMask layerMask = -1;

		// Token: 0x0400080E RID: 2062
		public PlaygroundBrushC brush;

		// Token: 0x0400080F RID: 2063
		public bool exceedMaxStopsPaint;

		// Token: 0x04000810 RID: 2064
		public bool initialized;
	}
}
